/***********************************************************************
* Copyright  2023 客户公司名称
* @URL: 
* @ProjectName: 项目名称
* @Description: 功能描述                            学习分页1
* Modification Log :
------------------------------------------------------------------------
* Developer                   Date                   Description
* ----------------------------------------------------------------------
* name 陈秋雨			2023-11-05      NULL 
***********************************************************************/
public with sharing class PaginationController {
    public Integer targetPageNumber { get; set; }//指定页码
    public ApexPages.StandardSetController standardSetController { get; set; }
    public String errorMessage { get; set; }//错误信息

    public PaginationController(ApexPages.StandardSetController controller) {
        standardSetController = controller;
        targetPageNumber = 1; // 默认跳转到第一页
        errorMessage = null;
    }

    public PageReference goToPage() {
        if (targetPageNumber <= 0 || targetPageNumber > Math.ceil(standardSetController.getResultSize() / standardSetController.getPageSize() ) ) {
            errorMessage = '请输入有效的页码';
            return null;
        }else{
            // 页码符合规范，继续执行逻辑
            standardSetController.setPageNumber(targetPageNumber);
            errorMessage = null;
            return null;
        }

        
    }
}